﻿-- Author      : Kurapica
-- Create Date : 12/22/2008

--[[
    In-Game Addon System
	Studio
	Code Form
--]]
do	
    local L = IGAS:NewLocal("IGAS.Studio")
    local CreateFrame = IGAS.GUI.CreateFrame
    local pairs = pairs
    local ipairs = ipairs
    local type = type
    local error = error
	
	-- Base Form for all other forms in Studio
    local coreF = CreateFrame("Frame", "IGAS_Studio")
	
	-- Code Form
    local codeF = CreateFrame("Form", "CodeForm", coreF)
    codeF.Visible = false
    codeF:SetPoint("CENTER", coreF, "CENTER")
    codeF.Caption = "In-Game Addon Studio"
    codeF.ClampedToScreen = true
    
	-- File List
    local fileTree = CreateFrame("TreeView", "FileList", codeF)
    fileTree:SetPoint("TOPLEFT", codeF, "TOPLEFT", 10, -26)
    fileTree:SetPoint("BOTTOMLEFT", codeF, "BOTTOMLEFT", 10, 26)
    fileTree:SetMinResize(100,200)
    fileTree:SetMaxResize(300,800)
    fileTree.Resizable = true
    fileTree.Width = 100
    
	-- Script TabGroup
    local tabCode = CreateFrame("TabGroup", "TabCode", codeF)
    tabCode:SetPoint("TOPRIGHT", codeF, "TOPRIGHT", -10, -26)
    tabCode:SetPoint("BOTTOMRIGHT", codeF, "BOTTOMRIGHT", -10, 26)
    tabCode:SetMinResize(200,200)
    tabCode:SetPoint("TOPLEFT", fileTree, "TOPRIGHT", 5, 0)
    
	-- Seperate Bar
    local seperateF = CreateFrame("Frame", "Seperate", codeF)
    seperateF.MouseEnabled = true
	seperateF:SetPoint("TOPLEFT", fileTree, "TOPRIGHT")
    seperateF:SetPoint("BOTTOMLEFT", fileTree, "BOTTOMRIGHT")
    seperateF:SetPoint("TOPRIGHT", tabCode, "TOPLEFT")
	seperateF:SetPoint("BOTTOMRIGHT", tabCode, "BOTTOMLEFT")
	
    --- HighLightTexture
	local highLight = CreateFrame("Texture", "HighLight", seperateF, "BACKGROUND")
	highLight:SetTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight")
	highLight:SetBlendMode("ADD")
	highLight:SetAllPoints(seperateF)
	highLight.Visible = false
	
	-- Project Menu
	local projectMenu = CreateFrame("DropDownList", "ProjectMenu", fileTree)
    projectMenu.NotDispose = true
	--- New Project Button
	local newProject = projectMenu:AddMenuButton("NewProject")
	newProject.Text = L["New Project"]
	--- Rename Project Button
	local renameProject = projectMenu:AddMenuButton("RenameProject")
	renameProject.Text = L["Rename Project"]
	--- Delete Project Button
	local delProject = projectMenu:AddMenuButton("DelProject")
	delProject.Text = L["Delete Project"]
	--- Add Script Button
	local addScript = projectMenu:AddMenuButton("AddScript")
	addScript.Text = L["Add Script"]
	
	-- Script Menu
	local fileMenu = CreateFrame("DropDownList", "FileMenu", fileTree)
    fileMenu.NotDispose = true
	--- Rename Script Button
	local renameScript = fileMenu:AddMenuButton("RenameScript")
	renameScript.Text = L["Rename Script"]
	--- Delete Script Button
	local delScript = fileMenu:AddMenuButton("DelScript")
	delScript.Text = L["Delete Script"]
	--- Move Up Button
	local upScript = fileMenu:AddMenuButton("UpScript")
	upScript.Text = L["Load Early"]
	--- Move Down Button
	local downScript = fileMenu:AddMenuButton("DownScript")
	downScript.Text = L["Load Later"]
	
	-- Script
	local function AddProject(prjName)
		local prj = fileTree:AddNode{["Text"] = prjName, ["Value"] = prjName}
		if prj then
			prj.Menu = projectMenu
		end
	end
	
	local function AddScript()
	end
		
	-- Event Handler
	--- Seperate Bar
	seperateF.OnEnter = function(self)
		seperateF:GetChild("HighLight").Visible = true
	end	
	seperateF.OnLeave = function(self)
		seperateF:GetChild("HighLight").Visible = false
	end	
    seperateF.OnMouseDown = function(self)
		fileTree:StartSizing("RIGHT")
    end	
    seperateF.OnMouseUp = function(self)
        fileTree:StopMovingOrSizing()
        fileTree:SetPoint("TOPLEFT", codeF, "TOPLEFT", 10, -26)
		fileTree:SetPoint("BOTTOMLEFT", codeF, "BOTTOMLEFT", 10, 26)
    end
	
	--- MenuButtons
	newProject.OnClick = function(self)
	end
	renameProject.OnClick = function(self)
	end
	delProject.OnClick = function(self)
	end
	addScript.OnClick = function(self)
	end
	renameScript.OnClick = function(self)
	end
	delScript.OnClick = function(self)
	end
	upScript.OnClick = function(self)
	end
	downScript.OnClick = function(self)
	end
end